home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 015a / memsz160.zip / SUPPORT.C < prev    next >
Text File  |  1992-12-16  |  22KB  |  550 lines

  1. /****************************************************************** SUPPORT.C
  2.  *                                                                          *
  3.  *                Presentation Manager Support Functions                    *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_WIN
  8. #include <os2.h>
  9.  
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "support.h"
  16.  
  17.  
  18. /****************************************************************************
  19.  *                                                                          *
  20.  *                        Message Dispatcher                                *
  21.  *                                                                          *
  22.  ****************************************************************************/
  23.  
  24. extern MRESULT DispatchMessage
  25. (
  26.   HWND    hwnd,
  27.   USHORT  msg,
  28.   MPARAM  mp1,
  29.   MPARAM  mp2,
  30.   PMETHOD MethodTable,
  31.   USHORT  MethodCount,
  32.   PFNWP   DefaultProcessor
  33. )
  34. {
  35.  /***************************************************************************
  36.   * Local Declarations                                                      *
  37.   ***************************************************************************/
  38.  
  39.   USHORT cNumberLeft ;
  40.   MRESULT mr ;
  41.   PMETHOD pMethod ;
  42.  
  43.  /***************************************************************************
  44.   * Process messages according to object's class method table.              *
  45.   ***************************************************************************/
  46.  
  47.   pMethod = MethodTable ;
  48.   cNumberLeft = MethodCount ;
  49.  
  50.   while ( ( cNumberLeft ) AND ( pMethod->Action != msg ) )
  51.   {
  52.     pMethod ++ ;
  53.     cNumberLeft -- ;
  54.   }
  55.  
  56.   if ( cNumberLeft )
  57.   {
  58.     mr = pMethod->pFunction ( hwnd, msg, mp1, mp2 ) ;
  59.   }
  60.   else
  61.   {
  62.     if ( DefaultProcessor )
  63.       mr = DefaultProcessor ( hwnd, msg, mp1, mp2 ) ;
  64.     else
  65.       mr = 0 ;
  66.   }
  67.  
  68.  /***************************************************************************
  69.   * Return result from message processor.                                   *
  70.   ***************************************************************************/
  71.  
  72.   return ( mr ) ;
  73. }
  74.  
  75. /****************************************************************************
  76.  *                                                                          *
  77.  *                         Add Item to System Menu                          *
  78.  *                                                                          *
  79.  ****************************************************************************/
  80.  
  81. extern VOID AddSysMenuItem ( HWND hwndFrame, MENUITEM *Item, PSZ Text )
  82. {
  83.  /***************************************************************************
  84.   * Local Declarations                                                      *
  85.   ***************************************************************************/
  86.  
  87.   HWND hwndSysMenu ;
  88.   HWND hwndSysSubMenu ;
  89.   USHORT idSysMenu ;
  90.   MENUITEM miSysMenu ;
  91.  
  92.  /***************************************************************************
  93.   * Obtain the system menu window handle.                                   *
  94.   ***************************************************************************/
  95.  
  96.   hwndSysMenu = WinWindowFromID ( hwndFrame, FID_SYSMENU ) ;
  97.  
  98.  /***************************************************************************
  99.   * Get the system menu's base item and its window handle.                  *
  100.   ***************************************************************************/
  101.  
  102.   idSysMenu = SHORT1FROMMR ( WinSendMsg ( hwndSysMenu, MM_ITEMIDFROMPOSITION, NULL, NULL ) ) ;
  103.  
  104.   WinSendMsg ( hwndSysMenu, MM_QUERYITEM,
  105.     MPFROM2SHORT(idSysMenu,FALSE), MPFROMP(&miSysMenu) ) ;
  106.  
  107.   hwndSysSubMenu = miSysMenu.hwndSubMenu ;
  108.  
  109.  /***************************************************************************
  110.   * Add the new item to the system menu's submenu, which is what we see.    *
  111.   ***************************************************************************/
  112.  
  113.   WinSendMsg ( hwndSysSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  114. }
  115.  
  116. /****************************************************************************
  117.  *                                                                          *
  118.  *                   Add Item to Submenu on System Menu                     *
  119.  *                                                                          *
  120.  ****************************************************************************/
  121.  
  122. extern VOID AddSysSubMenuItem
  123. (
  124.   HWND hwndFrame,
  125.   USHORT SubMenuID,
  126.   MENUITEM *Item,
  127.   PSZ Text
  128. )
  129. {
  130.  /***************************************************************************
  131.   * Local Declarations                                                      *
  132.   ***************************************************************************/
  133.  
  134.   HWND hwndSubMenu ;
  135.   HWND hwndSysMenu ;
  136.   HWND hwndSysSubMenu ;
  137.   USHORT idSysMenu ;
  138.   MENUITEM MenuItem ;
  139.  
  140.  /***************************************************************************
  141.   * Obtain the system menu window handle.                                   *
  142.   ***************************************************************************/
  143.  
  144.   hwndSysMenu = WinWindowFromID ( hwndFrame, FID_SYSMENU ) ;
  145.  
  146.  /***************************************************************************
  147.   * Get the system menu's base item and its window handle.                  *
  148.   ***************************************************************************/
  149.  
  150.   idSysMenu = SHORT1FROMMR ( WinSendMsg ( hwndSysMenu, MM_ITEMIDFROMPOSITION, NULL, NULL ) ) ;
  151.  
  152.   WinSendMsg ( hwndSysMenu, MM_QUERYITEM,
  153.     MPFROM2SHORT(idSysMenu,FALSE), MPFROMP(&MenuItem) ) ;
  154.  
  155.   hwndSysSubMenu = MenuItem.hwndSubMenu ;
  156.  
  157.  /***************************************************************************
  158.   * Get the submenu's base item and its window handle.                      *
  159.   ***************************************************************************/
  160.  
  161.   WinSendMsg ( hwndSysSubMenu, MM_QUERYITEM,
  162.     MPFROM2SHORT ( SubMenuID, TRUE ),
  163.     (MPARAM) &MenuItem ) ;
  164.  
  165.   hwndSubMenu = MenuItem.hwndSubMenu ;
  166.  
  167.  /***************************************************************************
  168.   * Add the new item to the system menu's submenu, which is what we see.    *
  169.   ***************************************************************************/
  170.  
  171.   WinSendMsg ( hwndSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  172. }
  173.  
  174. /****************************************************************************
  175.  *                                                                          *
  176.  *                           Add Item to Menu                               *
  177.  *                                                                          *
  178.  ****************************************************************************/
  179.  
  180. extern VOID AddMenuItem
  181. (
  182.   HWND hwndFrame,
  183.   USHORT MenuID,
  184.   MENUITEM *Item,
  185.   PSZ Text
  186. )
  187. {
  188.  /***************************************************************************
  189.   * Local Declarations                                                      *
  190.   ***************************************************************************/
  191.  
  192.   HWND hwndMenu ;
  193.  
  194.  /***************************************************************************
  195.   * Obtain the menu window handle.                                          *
  196.   ***************************************************************************/
  197.  
  198.   hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  199.  
  200.  /***************************************************************************
  201.   * Add the new item to the menu.                                           *
  202.   ***************************************************************************/
  203.  
  204.   WinSendMsg ( hwndMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  205. }
  206.  
  207. /****************************************************************************
  208.  *                                                                          *
  209.  *                        Add Item to SubMenu                               *
  210.  *                                                                          *
  211.  ****************************************************************************/
  212.  
  213. extern VOID AddSubMenuItem
  214. (
  215.   HWND hwndFrame,
  216.   USHORT MenuID,
  217.   USHORT SubMenuID,
  218.   MENUITEM *Item,
  219.   PSZ Text
  220. )
  221. {
  222.  /***************************************************************************
  223.   * Local Declarations                                                      *
  224.   ***************************************************************************/
  225.  
  226.   HWND hwndMenu ;
  227.   HWND hwndSubMenu ;
  228.   MENUITEM MenuItem ;
  229.  
  230.  /***************************************************************************
  231.   * Obtain the menu window handle.                                          *
  232.   ***************************************************************************/
  233.  
  234.   hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  235.  
  236.  /***************************************************************************
  237.   * Obtain the submenu window handle.                                       *
  238.   ***************************************************************************/
  239.  
  240.   WinSendMsg ( hwndMenu, MM_QUERYITEM,
  241.     MPFROM2SHORT ( SubMenuID, TRUE ),
  242.     (MPARAM) &MenuItem ) ;
  243.  
  244.   hwndSubMenu = MenuItem.hwndSubMenu ;
  245.  
  246.  /***************************************************************************
  247.   * Add the new item to the menu.                                           *
  248.   ***************************************************************************/
  249.  
  250.   WinSendMsg ( hwndSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text) ) ;
  251. }
  252.  
  253. /****************************************************************************
  254.  *                                                                          *
  255.  *      Enable/Disable menu item.                                           *
  256.  *                                                                          *
  257.  ****************************************************************************/
  258.  
  259. extern VOID EnableMenuItem ( HWND hwndFrame, USHORT MenuID, USHORT ItemID, BOOL Enable )
  260. {
  261.  /***************************************************************************
  262.   * Local Declarations                                                      *
  263.   ***************************************************************************/
  264.  
  265.   HWND hwndMenu ;
  266.  
  267.  /***************************************************************************
  268.   * Get the menu's window handle.                                           *
  269.   ***************************************************************************/
  270.  
  271.   hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  272.  
  273.  /***************************************************************************
  274.   * Set the menu item's enable/disable status.                              *
  275.   ***************************************************************************/
  276.  
  277.   WinSendMsg ( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT ( ItemID, TRUE ),
  278.     MPFROM2SHORT ( MIA_DISABLED, Enable ? 0 : MIA_DISABLED ) ) ;
  279. }
  280.  
  281. /****************************************************************************
  282.  *                                                                          *
  283.  *      Check/Uncheck menu item.                                            *
  284.  *                                                                          *
  285.  ****************************************************************************/
  286.  
  287. extern VOID CheckMenuItem ( HWND hwndFrame, USHORT MenuID, USHORT ItemID, BOOL Enable )
  288. {
  289.  /***************************************************************************
  290.   * Local Declarations                                                      *
  291.   ***************************************************************************/
  292.  
  293.   HWND hwndMenu ;
  294.  
  295.  /***************************************************************************
  296.   * Get the menu's window handle.                                           *
  297.   ***************************************************************************/
  298.  
  299.   hwndMenu = WinWindowFromID ( hwndFrame, MenuID ) ;
  300.  
  301.  /***************************************************************************
  302.   * Set the menu item's enable/disable status.                              *
  303.   ***************************************************************************/
  304.  
  305.   WinSendMsg ( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT ( ItemID, TRUE ),
  306.     MPFROM2SHORT ( MIA_CHECKED, Enable ? MIA_CHECKED : 0 ) ) ;
  307. }
  308.  
  309. /****************************************************************************
  310.  *                                                                          *
  311.  *                        Add Program to Task List                          *
  312.  *                                                                          *
  313.  ****************************************************************************/
  314.  
  315. extern VOID Add2TaskList ( HWND hwnd, PSZ Name )
  316. {
  317.  /***************************************************************************
  318.   * Local Declarations                                                      *
  319.   ***************************************************************************/
  320.  
  321.   PID pid ;
  322.   SWCNTRL swctl ;
  323.  
  324.  /***************************************************************************
  325.   * Get the window's process ID.                                            *
  326.   ***************************************************************************/
  327.  
  328.   WinQueryWindowProcess ( hwnd, &pid, NULL ) ;
  329.  
  330.  /***************************************************************************
  331.   * Add an entry to the system task list.                                   *
  332.   ***************************************************************************/
  333.  
  334.   swctl.hwnd = hwnd ;
  335.   swctl.hwndIcon = NULL ;
  336.   swctl.hprog = NULL ;
  337.   swctl.idProcess = pid ;
  338.   swctl.idSession = 0 ;
  339.   swctl.uchVisibility = SWL_VISIBLE ;
  340.   swctl.fbJump = SWL_JUMPABLE ;
  341.   strcpy ( swctl.szSwtitle, Name ) ;
  342.  
  343.   WinAddSwitchEntry ( &swctl ) ;
  344. }
  345.  
  346. /****************************************************************************
  347.  *                                                                          *
  348.  *      Process Exit menu command.                                          *
  349.  *                                                                          *
  350.  ****************************************************************************/
  351.  
  352. extern MRESULT APIENTRY Exit
  353. (
  354.   HWND hwnd,
  355.   USHORT msg,
  356.   MPARAM mp1,
  357.   MPARAM mp2
  358. )
  359. {
  360.  /***************************************************************************
  361.   * Send a WM_CLOSE message to the window.                                  *
  362.   ***************************************************************************/
  363.  
  364.   WinSendMsg ( hwnd, WM_CLOSE, 0L, 0L ) ;
  365.  
  366.  /***************************************************************************
  367.   * Done.                                                                   *
  368.   ***************************************************************************/
  369.  
  370.   return ( MRFROMSHORT ( 0 ) ) ;
  371.  
  372.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  373. }
  374.  
  375. /****************************************************************************
  376.  *                                                                          *
  377.  *      Process Help For Help menu command.                                 *
  378.  *                                                                          *
  379.  ****************************************************************************/
  380.  
  381. extern MRESULT APIENTRY HelpForHelp
  382. (
  383.   HWND hwnd,
  384.   USHORT msg,
  385.   MPARAM mp1,
  386.   MPARAM mp2
  387. )
  388. {
  389.  /***************************************************************************
  390.   * Local Declarations                                                      *
  391.   ***************************************************************************/
  392.  
  393.   HWND hwndHelp ;
  394.  
  395.  /***************************************************************************
  396.   * Get the help instance window handle, if any.                            *
  397.   ***************************************************************************/
  398.  
  399.   hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  400.  
  401.  /***************************************************************************
  402.   * If help is available, pass the request on to the help window.           *
  403.   ***************************************************************************/
  404.  
  405.   if ( hwndHelp )
  406.   {
  407.     WinSendMsg ( hwndHelp, HM_DISPLAY_HELP, 0L, 0L ) ;
  408.   }
  409.  
  410.  /***************************************************************************
  411.   * Done.                                                                   *
  412.   ***************************************************************************/
  413.  
  414.   return ( MRFROMSHORT ( 0 ) ) ;
  415.  
  416.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  417. }
  418.  
  419. /****************************************************************************
  420.  *                                                                          *
  421.  *      Process Extended Help menu command.                                 *
  422.  *                                                                          *
  423.  ****************************************************************************/
  424.  
  425. extern MRESULT APIENTRY ExtendedHelp
  426. (
  427.   HWND hwnd,
  428.   USHORT msg,
  429.   MPARAM mp1,
  430.   MPARAM mp2
  431. )
  432. {
  433.  /***************************************************************************
  434.   * Local Declarations                                                      *
  435.   ***************************************************************************/
  436.  
  437.   HWND hwndHelp ;
  438.  
  439.  /***************************************************************************
  440.   * Get the help instance window handle, if any.                            *
  441.   ***************************************************************************/
  442.  
  443.   hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  444.  
  445.  /***************************************************************************
  446.   * If help is available, pass the request on to the help window.           *
  447.   ***************************************************************************/
  448.  
  449.   if ( hwndHelp )
  450.   {
  451.     WinSendMsg ( hwndHelp, HM_EXT_HELP, 0L, 0L ) ;
  452.   }
  453.  
  454.  /***************************************************************************
  455.   * Done.                                                                   *
  456.   ***************************************************************************/
  457.  
  458.   return ( MRFROMSHORT ( 0 ) ) ;
  459.  
  460.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  461. }
  462.  
  463. /****************************************************************************
  464.  *                                                                          *
  465.  *      Process Keys Help menu command.                                     *
  466.  *                                                                          *
  467.  ****************************************************************************/
  468.  
  469. extern MRESULT APIENTRY KeysHelp
  470. (
  471.   HWND hwnd,
  472.   USHORT msg,
  473.   MPARAM mp1,
  474.   MPARAM mp2
  475. )
  476. {
  477.  /***************************************************************************
  478.   * Local Declarations                                                      *
  479.   ***************************************************************************/
  480.  
  481.   HWND hwndHelp ;
  482.  
  483.  /***************************************************************************
  484.   * Get the help instance window handle, if any.                            *
  485.   ***************************************************************************/
  486.  
  487.   hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  488.  
  489.  /***************************************************************************
  490.   * If help is available, pass the request on to the help window.           *
  491.   ***************************************************************************/
  492.  
  493.   if ( hwndHelp )
  494.   {
  495.     WinSendMsg ( hwndHelp, HM_KEYS_HELP, 0L, 0L ) ;
  496.   }
  497.  
  498.  /***************************************************************************
  499.   * Done.                                                                   *
  500.   ***************************************************************************/
  501.  
  502.   return ( MRFROMSHORT ( 0 ) ) ;
  503.  
  504.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  505. }
  506.  
  507. /****************************************************************************
  508.  *                                                                          *
  509.  *      Process Help Index menu command.                                    *
  510.  *                                                                          *
  511.  ****************************************************************************/
  512.  
  513. extern MRESULT APIENTRY HelpIndex
  514. (
  515.   HWND hwnd,
  516.   USHORT msg,
  517.   MPARAM mp1,
  518.   MPARAM mp2
  519. )
  520. {
  521.  /***************************************************************************
  522.   * Local Declarations                                                      *
  523.   ***************************************************************************/
  524.  
  525.   HWND hwndHelp ;
  526.  
  527.  /***************************************************************************
  528.   * Get the help instance window handle, if any.                            *
  529.   ***************************************************************************/
  530.  
  531.   hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  532.  
  533.  /***************************************************************************
  534.   * If help is available, pass the request on to the help window.           *
  535.   ***************************************************************************/
  536.  
  537.   if ( hwndHelp )
  538.   {
  539.     WinSendMsg ( hwndHelp, HM_HELP_INDEX, 0L, 0L ) ;
  540.   }
  541.  
  542.  /***************************************************************************
  543.   * Done.                                                                   *
  544.   ***************************************************************************/
  545.  
  546.   return ( MRFROMSHORT ( 0 ) ) ;
  547.  
  548.   hwnd = hwnd ;  msg = msg ;  mp1 = mp1 ;  mp2 = mp2 ;
  549. }
  550.